package com.mdd.admin.controller.course;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.course.ICourseCommentService;
import com.mdd.admin.validate.course.CourseCommentParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.course.CourseCommentListVo;
import com.mdd.admin.vo.course.CourseCommentDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 评论管理
 * @author panweiliang
 */
@RestController
@RequestMapping("api/course/comment")
public class CourseCommentController {

    @Resource
    ICourseCommentService iCourseCommentService;

    /**
     * 评论列表
     *
     * @author panweiliang
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<CourseCommentListVo> list = iCourseCommentService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 评论详情
     *
     * @author panweiliang
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CourseCommentDetailVo detail = iCourseCommentService.detail(id);
        return AjaxResult.success(detail);
    }


    /**
     * 编辑回复
     *
     * @author panweiliang
     * @param courseCommentParam 参数
     * @return Object
     */
    @Log(title = "评论编辑")
    @PostMapping("/reply")
    public Object reply(@Validated(value = CourseCommentParam.change.class) @RequestBody CourseCommentParam courseCommentParam) {
        iCourseCommentService.reply(courseCommentParam);
        return AjaxResult.success();
    }

    /**
     * 评论删除
     *
     * @author panweiliang
     * @param courseCommentParam 参数
     * @return Object
     */
    @Log(title = "评论删除")
    @PostMapping("/del")
    public Object del(@Validated(value = CourseCommentParam.delete.class) @RequestBody CourseCommentParam courseCommentParam) {
        iCourseCommentService.del(courseCommentParam.getId());
        return AjaxResult.success();
    }

}
